<template>
  <view class="voice-input-example">
    <view class="header">
      <text class="title">语音输入组件示例</text>
    </view>
    
    <!-- 简单语音输入示例 -->
    <view class="example-section">
      <text class="section-title">简单语音输入</text>
      <SimpleVoiceInput 
        v-model="simpleText"
        placeholder="点击麦克风说话..."
        :max-length="500"
        @transcript="onTranscript"
        @language-change="onLanguageChange"
      />
      <view class="result" v-if="simpleText">
        <text class="result-label">输入结果：</text>
        <text class="result-text">{{ simpleText }}</text>
      </view>
    </view>
    
    <!-- 完整语音识别示例 -->
    <view class="example-section">
      <text class="section-title">完整语音识别功能</text>
      <VoiceRecognition 
        :auto-start="false"
        :continuous="true"
        :max-duration="120"
        @transcript-update="onFullTranscriptUpdate"
        @recording-start="onRecordingStart"
        @recording-stop="onRecordingStop"
        @audio-recorded="onAudioRecorded"
      />
    </view>
    
    <!-- 使用说明 -->
    <view class="instructions">
      <text class="instructions-title">使用说明</text>
      <view class="instruction-list">
        <text class="instruction-item">• 点击麦克风按钮开始语音输入</text>
        <text class="instruction-item">• 支持多种语言识别</text>
        <text class="instruction-item">• 可以实时显示识别结果</text>
        <text class="instruction-item">• 支持音频录制和播放</text>
        <text class="instruction-item">• 支持音频文件上传识别</text>
      </view>
    </view>
  </view>
</template>

<script>
import SimpleVoiceInput from './SimpleVoiceInput.vue'
import VoiceRecognition from './VoiceRecognition.vue'

export default {
  name: 'VoiceInputExample',
  
  components: {
    SimpleVoiceInput,
    VoiceRecognition
  },
  
  data() {
    return {
      simpleText: '',
      fullTranscript: ''
    }
  },
  
  methods: {
    // 简单输入转录回调
    onTranscript(text) {
      console.log('转录文本:', text);
      uni.showToast({
        title: '识别成功',
        icon: 'success',
        duration: 1000
      });
    },
    
    // 语言切换回调
    onLanguageChange(language) {
      console.log('语言切换:', language);
      uni.showToast({
        title: `切换到${language}`,
        icon: 'none',
        duration: 1000
      });
    },
    
    // 完整转录更新回调
    onFullTranscriptUpdate(text) {
      this.fullTranscript = text;
      console.log('完整转录:', text);
    },
    
    // 录音开始回调
    onRecordingStart() {
      console.log('开始录音');
      uni.showToast({
        title: '开始录音',
        icon: 'none',
        duration: 1000
      });
    },
    
    // 录音停止回调
    onRecordingStop() {
      console.log('停止录音');
      uni.showToast({
        title: '录音结束',
        icon: 'none',
        duration: 1000
      });
    },
    
    // 音频录制完成回调
    onAudioRecorded(audioBlob) {
      console.log('音频录制完成:', audioBlob);
      // 这里可以上传音频到服务器或进行其他处理
    }
  }
}
</script>

<style scoped>
.voice-input-example {
  padding: 20px;
  max-width: 800px;
  margin: 0 auto;
}

.header {
  text-align: center;
  margin-bottom: 30px;
}

.title {
  font-size: 24px;
  font-weight: 600;
  color: #333;
}

.example-section {
  margin-bottom: 40px;
  padding: 20px;
  background: #f8f9fa;
  border-radius: 12px;
}

.section-title {
  display: block;
  font-size: 18px;
  font-weight: 600;
  color: #333;
  margin-bottom: 15px;
}

.result {
  margin-top: 15px;
  padding: 15px;
  background: white;
  border-radius: 8px;
  border-left: 4px solid #007bff;
}

.result-label {
  font-weight: 600;
  color: #666;
  display: block;
  margin-bottom: 8px;
}

.result-text {
  color: #333;
  line-height: 1.5;
}

.instructions {
  padding: 20px;
  background: #e3f2fd;
  border-radius: 12px;
}

.instructions-title {
  display: block;
  font-size: 18px;
  font-weight: 600;
  color: #1976d2;
  margin-bottom: 15px;
}

.instruction-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.instruction-item {
  color: #333;
  line-height: 1.5;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .voice-input-example {
    padding: 15px;
  }
  
  .title {
    font-size: 20px;
  }
  
  .section-title {
    font-size: 16px;
  }
  
  .example-section {
    padding: 15px;
  }
}
</style>